from users.models import User
from rest_framework import serializers

class UserSerilizers(serializers.ModelSerializer):
    class Meta:
        model=User
        fields=("id","username","mobile","email","password")

        # 添加额外的约束, write_only,只写,即可加密密码
        extra_kwargs={
            "password":{
                "write_only":True
            }
        }
        # 1,重写父类create方法,objects的create_user对密码加密处理
    def create(self, validated_data):
        return User.objects.create_user(**validated_data)